from rest_framework.response import Response
from rest_framework.views import APIView
from .models import *
from .ser import *


class UserAPIView(APIView):
    def get(self, request):
        username = request.data.get('username')
        password = request.data.get('password')
        user = User.objects.filter(name=username).first()
        pw = User.objects.filter(password=password).first()
        if username == user:
            if pw == password:
                return Response({'code': 200, 'msg': '登录成功'})


class NewsAPIView(APIView):
    def get(self, request):
        user = News.objects.all()
        ser = NewsSer(user, many=True)
        return Response(ser.data)
